package com.biscuit.page.basicservice.design.websocket.register.factory;

import com.biscuit.page.basicservice.design.websocket.register.WebSocketRegisterTypeEnum;
import com.biscuit.page.basicservice.design.websocket.register.strategy.AiChatSessionWebSocketRegisterHandlerStrategy;
import com.biscuit.page.basicservice.design.websocket.register.strategy.ChatRoomWebSocketRegisterHandler;
import com.biscuit.page.basicservice.design.websocket.register.strategy.WebSocketRegisterHandlerStrategy;
import com.biscuit.page.basicservice.utils.BaseExceptionUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author biscuit
 * @createTime 2024/6/22 14:21
 */
public class WebSocketRegisterHandlerFactory {

    private final static Map<WebSocketRegisterTypeEnum, WebSocketRegisterHandlerStrategy> FACTORY_MAP;

    static {
        FACTORY_MAP = new HashMap<>();
        FACTORY_MAP.put(WebSocketRegisterTypeEnum.CHAT_ROOM_REGISTER, new ChatRoomWebSocketRegisterHandler());
        FACTORY_MAP.put(WebSocketRegisterTypeEnum.AI_CHAT_SESSION_REGISTER, new AiChatSessionWebSocketRegisterHandlerStrategy());
    }

    public static WebSocketRegisterHandlerStrategy create(int type) {
        WebSocketRegisterTypeEnum typeEnum = WebSocketRegisterTypeEnum.getEnumByType(type);
        BaseExceptionUtil.throwException(Objects.nonNull(typeEnum), "WebSocket注册类型不存在");
        WebSocketRegisterHandlerStrategy strategy = FACTORY_MAP.get(typeEnum);
        BaseExceptionUtil.throwException(Objects.nonNull(strategy), "WebSocket注册处理逻辑未实现");
        return strategy;
    }

}
